package com.example.dc.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class JWTUtils {
    //生成token
    public String setToken(String account) {
        Map<String, Object> claims = new HashMap<>();
        claims.put("phone", account);
        String token = Jwts.builder().signWith(SignatureAlgorithm.HS256, "pencil").setClaims(claims).setExpiration(new Date(System.currentTimeMillis() + 30L * 24 * 60 * 60 * 1000)).compact();
        return token;
    }

    //解析令牌
    public void parseToken(String token){
        Claims claims=Jwts.parser().setSigningKey("pencil").parseClaimsJws(token).getBody();
    }
}
